package org.example;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class test05 {
    public static void main(String[] args) {

        //录入成绩
        List<Double> scores = new ArrayList<>();
        Collections.addAll(scores, 1.1, 2.2, 3.3, 4.4, 5.5, 0.0);
        //1.找出大于等于三分并排序输出
        scores.stream().filter(s -> s >= 3).sorted().forEach(s -> System.out.println(s));

        //录入学生信息
        List<Students> students = new ArrayList<>();
        Students students1 = new Students("小a", 15);
        Students students2 = new Students("小b", 17);
        Students students3 = new Students("小c", 19);
        Students students4 = new Students("小d", 25);
        Students students5 = new Students("小e", 10);
        Students students6 = new Students("小f", 33);
        Collections.addAll(students, students1, students2, students3, students4, students5, students6);

        //2.找出年龄大于等于18且年纪小于30的学生，按照年龄降序输出
//        try {
//            students.stream().filter(s ->(s.age>=18 && s.age<30)).sorted().forEach(s -> System.out.println(s));
//
//        } catch (Exception e) {
//            throw new RuntimeException(e);}
// 错误，不可行那就应该传入比较器
        students.stream().filter(s -> (s.age >= 18 && s.age < 30)).sorted(((o1, o2) -> o1.age - o2.age))
                .forEach(System.out::println);
        //输出的是地址所以需要重写toString方法

        //3.取出年龄最大的三名学生并输出
        students.stream().sorted(((o1, o2) -> o2.age - o1.age)).limit(3).forEach(s -> System.out.println(s));

    }

}
